package caiziyou.com.designpattern.singleton.type6;

/**
 * 
 * 懒汉式 线程不安全的 不能解觉效率问题和线程问题 在实际开发中不能使用
 * 
 * @author Administrator
 *
 */
public class SingletonTest06 {
	public static void main(String[] args) {
		Singleton instance1 = Singleton.getInstance();
		Singleton instance2 = Singleton.getInstance();
		System.out.println(instance1 == instance2);
	}

}

class Singleton {

	private Singleton() {
	}

	private static volatile Singleton instance;

	public static Singleton getInstance() {
		if (instance == null) {
			synchronized (Singleton.class) {
				if (instance == null) {
					instance = new Singleton();
				}
			}
		}
		return instance;
	}

}
